package com.xiaoxing.salesclient.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.xiaoxing.gifloadingview.LoadingDialogUtil;
import com.xiaoxing.salesclient.di.component.DaggerYiShiXiangQingComponent;
import com.xiaoxing.salesclient.di.module.YiShiXiangQingModule;
import com.xiaoxing.salesclient.mvp.contract.YiShiXiangQingContract;
import com.xiaoxing.salesclient.mvp.model.entity.AppointDetail;
import com.xiaoxing.salesclient.mvp.presenter.YiShiXiangQingPresenter;

import butterknife.BindView;
import me.jessyan.armscomponent.commonres.utils.ToolbarUtils;
import me.jessyan.armscomponent.commonsdk.core.BaseConstants;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;
import me.jessyan.armscomponent.commonsdk.utils.WebviewUtil;
import xiaoxing.com.salesclient.R;
import xiaoxing.com.salesclient.R2;

import static com.jess.arms.utils.Preconditions.checkNotNull;


@Route(path = RouterHub.SALES_CLIENT_YI_SHI_XIANG_QING_ACTIVITY)
public class YiShiXiangQingActivity extends BaseActivity<YiShiXiangQingPresenter> implements YiShiXiangQingContract.View {
    @Autowired
    String doctor_id;
    @BindView(R2.id.tv_name)
    TextView tvName;
    @BindView(R2.id.tv_jian_jie)
    WebView tvJianJie;
    @BindView(R2.id.img_head)
    ImageView imgHead;
    @BindView(R2.id.tv_xue_xi_jing_yan)
    TextView tvXueXiJingYan;
    @BindView(R2.id.tv_zhi_ye_jing_yan)
    TextView tvZhiYeJingYan;
    @BindView(R2.id.tv_suo_huo_jiang_xiang)
    TextView tvSuoHuoJiangXiang;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerYiShiXiangQingComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .yiShiXiangQingModule(new YiShiXiangQingModule(this))
                .build()
                .inject(this);
        ARouter.getInstance().inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_yi_shi_xiang_qing; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        ToolbarUtils.initToolbarTitleBack(this, "醫師詳情");

        mPresenter.appointDetail(mSharedPreferencesHelper.getString(BaseConstants.TOKEN), doctor_id);
    }

    @Override
    public void showLoading() {

        LoadingDialogUtil.showGifdialog2(getSupportFragmentManager(), R.drawable.public_loading);
    }

    @Override
    public void hideLoading() {
        LoadingDialogUtil.dismissDialog();
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public void appointDetailSuccessed(AppointDetail appointDetail) {

        if (appointDetail != null && appointDetail.getData() != null) {

            AppointDetail.DataBean dataBean = appointDetail.getData();

            tvName.setText(dataBean.getDoctor_name());
            WebviewUtil.loadData(this, tvJianJie, dataBean.getInfo());
            tvXueXiJingYan.setText(dataBean.getStudy());
            tvZhiYeJingYan.setText(dataBean.getTeach());
            tvSuoHuoJiangXiang.setText(dataBean.getPrize());
            Glide.with(this).load(dataBean.getCover()).into(imgHead);
        }
    }


}
